package cn.zsb.service;

import cn.zsb.dao.UserDao;
import cn.zsb.entity.Page;
import cn.zsb.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;


import java.util.Date;
import java.util.List;
@Service
@CacheConfig(keyGenerator = "keyg")
@Cacheable(cacheNames = "student")
//@Cacheable(keyGenerator = "keyg",cacheNames = "student")
public class UserService {

    public static final Logger Log = LoggerFactory.getLogger(UserService.class);

    @Autowired
    private UserDao dao;

    public int add(User user) {
        return dao.add(user);
    }

    public int update(User adv) {

        return dao.update(adv);

    }

    public int del(long id) {

        return dao.del(id);

    }

    public User get(long id) {

        return dao.get(id);

    }

//    public List<User> findAll() {
//
//        List<User> list = dao.findAll();
//        return dao.findAll();
//
//    }

    public Page<User> page(String sname, String phone, Date start, Date end, int pageNo, int pageSize) {

        List<User> list = dao.search1(sname, phone,start,end, pageNo, pageSize);
        int total = dao.findTotal(sname, phone,start,end);
        return new Page<>(list, pageNo, total, pageSize);

    }

    public int findTotal(String sname,  String phone, Date start, Date end) {

        return dao.findTotal(sname, phone,start,end);

    }

    public int checkopenid(String openid, long id) {

        return dao.checkopenid(openid, id);

    }
}
